/**
 * 
 */
package test.main;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;

import org.hibernate.SessionFactory;
import org.jboss.logging.Message;

import de.vogella.rss.model.Feed;
import de.vogella.rss.model.FeedMessage;
import de.vogella.rss.read.RSSFeedParser;

import buisness.local.hibernate.model.Anime;
import buisness.local.hibernate.model.Fansub;
import buisness.local.hibernate.service.BusinessService;
import buisness.local.hibernate.util.HibernateUtil;

/**
 * @author Skap3
 *
 */
public class mainv1 {
	
	@PersistenceContext(unitName="vap",type=PersistenceContextType.TRANSACTION)
	protected EntityManager entityManagerAmbito;

	/**
	 * 
	 */
	public mainv1() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		System.out.println(" --- INICIAMOS EJECUCION --- ");
		
		try {
			
			List<Fansub> resultado = BusinessService.getAllFansub();
			System.out.println("N resultados: "+resultado.size());
			
			RSSFeedParser feedParser;
			Feed feed;
			
			for (Fansub fansub : resultado){
				if (fansub.getFeed() != null && !fansub.getFeed().equalsIgnoreCase("") ){
					System.out.println("---------------------------------------------------------------");
					try{
						feedParser = new RSSFeedParser(fansub.getFeed());
						feed = feedParser.readFeed();
						System.out.println(feed.toString());
						for (FeedMessage message : feed.getMessages()){
							System.out.println(fansub.getEtiqueta()+" "+message.getTitle());
						}
					} catch (Exception ex2){
						System.out.println("ERROR EN FEED: "+fansub.getNombre());
					}
				}
			}
			

		} catch (Exception e){
			e.printStackTrace();
		}
		
		System.out.println(" --- FINALIZAMOS EJECUCION --- ");

	}

}
